<?php

namespace App\Services;

class TaxService
{
    /**
     * 计算个人所得税
     *
     * @param float $income 收入金额
     * @param string $taxType 税种类型
     * @return array
     */
    public function calculatePersonalTax($income, $taxType = 'freelancer')
    {
        // Mock实现 - 简单税率计算
        \Log::info('Tax Mock: 计算个人所得税', [
            'income' => $income,
            'tax_type' => $taxType
        ]);
        
        // 模拟累进税率计算
        $taxRate = 0.20; // 20%税率
        $taxAmount = $income * $taxRate;
        $afterTaxIncome = $income - $taxAmount;
        
        return [
            'success' => true,
            'income' => $income,
            'tax_rate' => $taxRate,
            'tax_amount' => round($taxAmount, 2),
            'after_tax_income' => round($afterTaxIncome, 2),
            'calculation_details' => [
                'base_amount' => $income,
                'deductions' => 0,
                'taxable_income' => $income,
                'tax_brackets' => [
                    ['rate' => 0.20, 'amount' => $taxAmount]
                ]
            ]
        ];
    }
    
    /**
     * 计算企业税
     *
     * @param float $revenue 营业收入
     * @param float $costs 成本
     * @return array
     */
    public function calculateCorporateTax($revenue, $costs = 0)
    {
        // Mock实现
        \Log::info('Tax Mock: 计算企业税', [
            'revenue' => $revenue,
            'costs' => $costs
        ]);
        
        $profit = $revenue - $costs;
        $taxRate = 0.25; // 25%企业所得税率
        $taxAmount = $profit * $taxRate;
        
        return [
            'success' => true,
            'revenue' => $revenue,
            'costs' => $costs,
            'profit' => $profit,
            'tax_rate' => $taxRate,
            'tax_amount' => round($taxAmount, 2),
            'after_tax_profit' => round($profit - $taxAmount, 2)
        ];
    }
}